#ifndef __NEZHE_ALLOCATOR_H__
#define __NEZHE_ALLOCATOR_H__

#include "FoundationPredefine.h"
#include "FoundationLibType.h"

namespace Nezha
{
	// Allocator prototype
	class  FOUNDATION_ENTRY Allocator
	{
	public:
		virtual ~Allocator(){}

		virtual void* malloc(size_t bytes) = 0;

		virtual void* realloc(void * p, size_t bytes) = 0;

		virtual void free(void* p) = 0;

		// TODO aligned alloc

	};

	// Memory tracker prototype
	class FOUNDATION_ENTRY MemTracker
	{
	public:
		virtual ~MemTracker(){}

		virtual void push(void* p, size_t bytes, const char* fileName, int line) = 0;

		virtual void pushArray(void* p, size_t bytes, const char* fileName, int line) = 0;

		virtual void pop(void* p) = 0;

		virtual void popArray(void* p) = 0;

		virtual void dumpMemoryLeak() {}
	};

}


class FOUNDATION_ENTRY NZAllocator
{
public:
	static Nezha::Allocator* GetInstance()
	{
		return msAllocator;
	}

	// REMARKS
	// if use external allocator, initialize at the beginning with this entry.
	static void InitializeWithUserAllocator(Nezha::Allocator* alloc);
private:
	static Nezha::Allocator* msAllocator;
};


class FOUNDATION_ENTRY NZMemoryTrack
{
public:
	static Nezha::MemTracker* GetInstance()
	{
		return msTracker;
	}

	// REMARKS
	// if use external tracker, initialize at the beginning with this entry.
	static void InitializeWithUserTracker(Nezha::MemTracker* tracker);

private:
	static Nezha::MemTracker* msTracker;
};

#endif //end __NEZHE_ALLOCATOR_H__